package wiz.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;

import wiz.client.WizService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class WizRemoteServiceImpl extends RemoteServiceServlet implements WizService{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String getPlayerNames() {
		try {
			InputStream openConnection = new URL("http://wiz.chruszcz.ca/entry").openStream(); //$NON-NLS-1$
			StringWriter response = new StringWriter();
			PrintWriter pr = new PrintWriter(response);
			BufferedReader br = new BufferedReader(new InputStreamReader(openConnection));
			String line;
			while((line = br.readLine()) != null){
				pr.println(line);
			}
			
			pr.flush();
			return response.toString();
		} catch (MalformedURLException e) {
			return null;
		} catch (IOException e) {
			return null;
		}
	}

}
